//
//  MainViewController.m
//  PopCar
//
//  Created by qianfeng on 15/10/20.
//  Copyright (c) 2015年 HXH. All rights reserved.
//

#import "MainViewController.h"
#import "FirstPageViewController.h"
#import "CarMarketViewController.h"
#import "DiscoverViewController.h"
#import "MineViewController.h"
#import "RDVTabBarItem.h"
#import "Macro.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpViewControllers];
}

-(void)setUpViewControllers
{
    //首页
    FirstPageViewController * firstPageVC = [[FirstPageViewController alloc]init];
    
    
    //车市
    CarMarketViewController * carMarketVC = [[CarMarketViewController alloc]init];
    
    //发现
    
    DiscoverViewController * discoverVC = [[DiscoverViewController alloc]init];
    
    
    //我的
    MineViewController * mineVC = [[MineViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:mineVC];
    nav.navigationBar.backgroundColor = [UIColor redColor];
    
    NSArray * items = @[firstPageVC,carMarketVC,discoverVC,nav];
    self.viewControllers = items;
    [self customizeTabBarForController:self];
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    NSArray * tabBarItemTitles = @[@"首页",@"车市",@"发现",@"我的"];
    NSArray * tabBarItemImages = @[@"tabbar_shouye",@"tabbar_carmarket",@"tabbar_faxian",@"tabbar_wo"];
    
    
    NSDictionary * selectedTitleAttributes = nil;
    NSDictionary * unselectedTitleAttributes = nil;
    
    if (NSFoundationVersionNumber >NSFoundationVersionNumber_iOS_6_1) {
        unselectedTitleAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:LiycRGB(147, 145, 145)};
        selectedTitleAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:LiycRGB(199, 57, 32)};
    }
    
    
    NSInteger index = 0;
    for (RDVTabBarItem * item in [[tabBarController tabBar] items]) {
        item.title = tabBarItemTitles[index];
        
        NSString * normalImagename = [NSString stringWithFormat:@"%@_normal.png",tabBarItemImages[index]];
        NSString * selectedImagename = [NSString stringWithFormat:@"%@_selected.png",tabBarItemImages[index]];
        //选中状态image
        UIImage * selectImage = [UIImage imageNamed:selectedImagename];
        //未选中状态image
        UIImage * normalImage = [UIImage imageNamed:normalImagename];
        [item setFinishedSelectedImage:selectImage withFinishedUnselectedImage:normalImage];
        item.selectedTitleAttributes = selectedTitleAttributes;
        item.unselectedTitleAttributes = unselectedTitleAttributes;
        index++;
    }
}


@end
